<?php

namespace app\store\controller;

use library\tools\Express;
use library\Controller;
use think\Db;

/**
 * 渠道数据
 * Class GoodsCate
 * @package app\store\controller
 */
class Player extends Controller
{
    /**
     * 绑定数据表
     * @var string
     */
    protected $table_DB_Platform_Account_library = 'db_platform_accounts';           /*平台账户配置库*/
    protected $table_DB_Platform_Account_log_library = 'db_platform_log';            /*平台日志库*/
    protected $table_DB_Platform_Account_library_platformdb = 'db_platform_qpplatformdb'; /*平台日志库*/
    protected $accounts_info = 'accounts_info';                                      /* 账户表 */
    protected $user_props_info = 'user_props_info';                                  /* 道具表 */
    protected $user_prop_log = 'user_prop_log';                                      /* 道具日志表 */
    protected $user_score_log = 'user_score_log';                                    /* 金币日志表 */
    protected $user_game_info = 'user_game_info';                                    /* 游戏用户表 */
    protected $user_bind_info = 'user_bind_info';                                    /* 手机号绑定 */
    protected $user_board_info = 'user_board_info';                                  /* 用户反馈表 */
    protected $user_mail_info = 'user_mail_info';                                    /* 邮件表*/
    protected function Db_connect_accounts_info()
    {
        $accounts_info = Db::connect($this->table_DB_Platform_Account_library)->table($this->accounts_info);
        return $accounts_info;
    }
    protected function Db_connect_user_board_info()
    {
        $user_board_info = Db::connect($this->table_DB_Platform_Account_library_platformdb)->table($this->user_board_info);
        return $user_board_info;
    }
    protected function Db_connect_user_mail_info()
    {
        $user_mail_info = Db::connect($this->table_DB_Platform_Account_library_platformdb)->table($this->user_mail_info);
        return $user_mail_info;
    }
    protected function Db_connect_user_bind_info()
    {
        $user_bind_info = Db::connect($this->table_DB_Platform_Account_library)->table($this->user_bind_info);
        return $user_bind_info;
    }
    protected function Db_connect_user_game_info()
    {
        $user_game_info= Db::connect($this->table_DB_Platform_Account_library)->table($this->user_game_info);
        return $user_game_info;
    }
    protected function Db_connect_user_props_info()
    {
        $user_props_info = Db::connect($this->table_DB_Platform_Account_library)->table($this->user_props_info);
        return $user_props_info;
    }
    protected function Db_connect_user_score_log()
    {
        $user_score_log = Db::connect($this->table_DB_Platform_Account_log_library)->table($this->user_score_log);
        return $user_score_log;
    }
    protected function Db_connect_user_prop_log()
    {
        $user_prop_log = Db::connect($this->table_DB_Platform_Account_log_library)->table($this->user_prop_log);
        return $user_prop_log;
    }
    /**
     * 用户查询
     * @auth true
     * @menu true
     * @throws \think\exception\PDOException
     */
    public function index()
    {
            $request = input('request.');
            $this->title = '用户查询';
            $list =$this->Db_connect_accounts_info()
                ->where($this->structure_where())
                ->order('RegisterDate desc')
                ->paginate(10,false,['query'=>$request]);
            $data = $list->all();
            foreach ($data as $k => $v) {
                $Cannon =$this->Db_connect_user_game_info()
                    ->where('UserID',$v['UserID'])
                    ->value('Cannon');
                $v['Cannon'] = $Cannon;
                $channel_name = get_channel_name($v['SpreaderID']);
                $v['channel_name'] = $channel_name;
                $list[$k] = $v;
            }
            $start_time = date('Y-m-d', time()) . ' - ' . date('Y-m-d', time()+24*3600);
            /*渠道类型*/
            $channel_arr = Specific_parameters_Recharge_channel_arr();
            $pages = $list->render();
            $this->assign('list',$list);
            $this->assign('start_time', $start_time);
            $this->assign('channel_arr', $channel_arr);
            $this->assign('pages', $pages);
            $this->fetch();
    }
    protected function structure_where()
    {
            $reg_time = $this->request->param('reg_time');
            $login_time = $this->request->param('login_time');
            $channel_type    = $this->request->param('channel_type');
            $UserID    = $this->request->param('UserID');
            $reg_ip    = $this->request->param('reg_ip');
            $login_ip    = $this->request->param('login_ip');
            $UniqueID    = $this->request->param('UniqueID');
            $ClientVersion    = $this->request->param('ClientVersion');
            $NickName    = $this->request->param('NickName');
            $where = [];
            if(!empty($UserID)){
                $where[] =['UserID','eq',$UserID];
            }
            if(!empty($NickName)){
                $where[] =['NickName','like',"%".$NickName."%"];
            }
            if(!empty($UniqueID)){
                $where[] =['UniqueID','eq',$UniqueID ];
            }
            if(!empty($reg_ip)){
                $where[] =['RegisterIP','eq',$reg_ip];
            }
            if(!empty($login_ip)){
                $where[] =['LastLoginIP','eq',$login_ip];
            }
            if(!empty($ClientVersion)){
                $where[] =['ClientVersion','eq',$ClientVersion];
            }
            if (!empty($reg_time)) {
                $list = explode(' - ', $reg_time);
                $begin = $list[0];
                $after = $list[1];
                $where[] = ['RegisterDate', 'between', [$begin, $after.' 23:59:59']];
            }
            if (!empty($login_time)) {
                $list = explode(' - ', $login_time);
                $begin = $list[0];
                $after = $list[1];
                $where[] = ['LastLoginDate', 'between', [$begin, $after.' 23:59:59']];
            }
            if(!empty($channel_type)){
                if($channel_type==30)$channel_type=0;
                $where[] =['SpreaderID','eq',$channel_type];
            }
            return $where;
    }
    /**
     * 我的背包
     * @auth true
     * @menu true
     * @throws \think\exception\PDOException
     */
    function backpack(){
             $UserID = $this->request->param('id');
             $list =$this->Db_connect_user_props_info()
                ->field('UserID,PropID,Counts,InserTime')
                ->where('UserID',$UserID)
                ->order('InserTime desc')
                ->select();
             foreach ($list as $k => $v) {
                 $v['prop_name'] = get_prop_name($v['PropID']);
                 $v['prop_description'] = get_prop_description($v['PropID']);
                 $list[$k] = $v;
             }
             $this->assign('list',$list);
             $this->fetch('pack_form');
    }
    /**
     * 玩家属性
     * @auth true
     * @menu true
     * @throws \think\exception\PDOException
     */
    function user_attribute(){
        $UserID = $this->request->param('id');
        /* 用户信息 */
        $user_info =$this->Db_connect_accounts_info()
            ->where('UserID',$UserID)
            ->find();
        $game_info =$this->Db_connect_user_game_info()
            ->where('UserID',$UserID)
            ->find();
        $bind_info =$this->Db_connect_user_bind_info()
            ->where('UserID',$UserID)
            ->find();
        $user_info ['LastLogin_city']=location_ip_area($user_info['LastLoginIP']);
        $user_info ['reg_city']=location_ip_area($user_info['RegisterIP']);
        $game_info ['GameTime']=round($game_info['GameTime']/60,2);
        $this->assign('user_info',$user_info);
        $this->assign('game_info',$game_info);
        $this->assign('bind_info',$bind_info);
        $this->fetch('attribute_form');
    }
    /**
     * 金币明细
     * @auth true
     * @menu true
     * @throws \think\exception\PDOException
     */
    function score_detail(){
            $UserID = $this->request->param('id');
            $list =$this->Db_connect_user_score_log()
                ->where('UserID',$UserID)
                ->order('ID desc')
                ->select();
            foreach ($list as $k => $v) {
                $v['game_room'] = room_type($v['GameName'],$v['GameLevel']);
                $list[$k] = $v;
            }
            $this->assign('list',$list);
            $this->fetch('score_form');
    }
    /**
     * 道具明细
     * @auth true
     * @menu true
     * @throws \think\exception\PDOException
     */
    function prop_detail(){
            $PropID = $this->request->param('PropID');
            $UserID = $this->request->param('id');
            $list =$this->Db_connect_user_prop_log()
                ->where('UserID',$UserID)
                ->where('PropID',$PropID)
                ->order('ID desc')
                ->select();
            foreach ($list as $k => $v) {
                $v['prop_name'] = get_prop_name($v['PropID']);
                $v['game_room'] = room_type($v['GameName'],$v['GameLevel']);
                $list[$k] = $v;
            }
            $this->assign('list',$list);
            $this->fetch('prop_form');
    }
    /**
     * 用户反馈
     * @auth true
     * @menu true
     * @throws \think\exception\PDOException
     */
    function message(){
        $request = input('request.');
        $this->title = '用户反馈';
        if (isset($request['Status']) and $request['Status'] != '') {
            $list = $this->Db_connect_user_board_info()
                ->where('Status', $request['Status'])
                ->order('RecordTime desc')
                ->paginate(30, false, ['query' => $request]);

        } else {
            $list = $this->Db_connect_user_board_info()
                ->order('RecordTime desc')
                ->paginate(30, false, ['query' => $request]);
        }
        $pages = $list->render();
        $this->assign('list',$list);
        $this->assign('pages', $pages);
        $this->fetch();
    }
    /**
     * 客服回复
     * @auth true
     * @menu true
     * @throws \think\exception\PDOException
     */
    function customer(){
        $request = input('request.');
        $this->title = '客户回复';
        $list =$this->Db_connect_user_mail_info()
            ->where("Sender",1001)
            ->order('InsertTime desc')
            ->paginate(10,false,['query'=>$request]);
        $pages = $list->render();
        $this->assign('list',$list);
        $this->assign('pages', $pages);
        $this->fetch();
    }
    /*限时道具*/
    function Time_limit_prop(){
        $UserID = $this->request->param('id');
        $data=time_prop_arr($UserID);
        $this->assign('list',$data);
        $this->fetch('time_limit_form');
    }

}
